<?php
/**
 * Cookie操作関数<br />
 *
 * @package apamanshop
 * @author　
 * @copyright　
 */
class Rstdtl_Model_Okiniiriinsert extends Rstdtl_Model_Base
{

	/**
	* マイページユーザCD取得
	*/
	public function getUserCd($eMail)
	{
		$db_params = array();

		$sql = $this->getUserCdSql($eMail, &$db_params);
		$data = $this->dbGetData($sql, $db_params);

		return $data['M92_USER_CD'];
	}

	/**
	* 登録物件重複確認
	*/
	public function getDuplicate($params)
	{
		$db_params = array();

		$sql = $this->duplicateSql($params, &$db_params);

		return $this->dbGetData($sql, $db_params);
	}

	/**
	* 登録物件数取得
	*/
	public function getCnt($params)
	{
		$db_params = array();

		$sql = $this->countSql($sql, $db_params);
		$data = $this->dbGetData($sql, $db_params);

		return $data['CNT'];
	}

	/**
	* お気に入り物件登録
	*/
	public function insertBuken($params,$db)
	{
		$db_params = array();

		$sql = $this->insertSql($params, $db_params);
		$this->dbExecQuery($sql,$db_params,$db);
	}

	/**
	* 登録物件重複確認取得SQL
	*/
	public function getUserCdSql($eMail, &$db_params)
	{
		$db_params["strUserId"] = $eMail;

		$sql .= "SELECT";
		$sql .= "        M92_USER_CD";
		$sql .= "    FROM";
		$sql .= "        M92MYPAGE_USER";
		$sql .= "    WHERE";
		$sql .= "        M92_E_MAIL = :strUserId ";
		$sql .= "        AND M92_DELETE_FLG = 0";

		return $sql;
	}

	/**
	* 登録物件重複確認取得SQL
	*/
	public function duplicateSql($params, &$db_params)
	{
		$db_params["strHeyaCd"] = $params["heyaCd"];
		$db_params["strUserCd"] = $params["UserCd"];

		$sql = "";
		$sql .= "SELECT * ";
		$sql .= "   FROM ";
		$sql .= "       T99FAVORITE ";
		$sql .= "   WHERE ";
		$sql .= "       T99_USER_CD = :strUserCd ";
		$sql .= "       AND T99_HEYA_CD = :strHeyaCd ";

		return $sql;

	}

	/**
	* お気に入り物件登録数取得SQL
	*/
	public function countSql($params, &$db_params)
	{
		$db_params["strUserCd"] = $params["UserCd"];

		$sql = "";
		$sql .= "SELECT ";
		$sql .= "     count(*) AS CNT ";
		$sql .= "  FROM ";
		$sql .= "      T99FAVORITE ";
		$sql .= "      ,T03WEB_HEYA ";
		$sql .= "  WHERE ";
		$sql .= "      T99_USER_CD = :strUserCd ";
		$sql .= "      AND T99_HEYA_CD = T03_HEYA_CD ";

		return $sql;
	}

	/**
	* お気に入り物件登録SQL
	*/
	public function insertSql($params, &$db_params)
	{
		$db_params["strHeyaCd"] = $params["heyaCd"];
		$db_params["strUserCd"] = $params["UserCd"];

		$sql = "";
		$sql .= "INSERT";
		$sql .= "    INTO";
		$sql .= "        T99FAVORITE(";
		$sql .= "            T99_USER_CD";
		$sql .= "            ,T99_HEYA_CD";
		$sql .= "            ,T99_TOUROKUBI";
		$sql .= "            ,T99_MYPAGE_KBN";
		$sql .= "        )";
		$sql .= "    VALUES";
		$sql .= "        (";
		$sql .= "            :strUserCd ";
		$sql .= "            , :strHeyaCd ";
		$sql .= "            ,SYSDATE";
		$sql .= "            ,'1'";
		$sql .= "        )";

		return $sql;
	}
}
?>